
// 413.等差数列划分
class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size();
        
        vector<int> dp(n);          //记录以i位置为结尾的最长等差数列
        int ret = 0;
        for(int i = 2; i < n ;i++)
        {
            if(2*nums[i-1] == nums[i] + nums[i-2]) dp[i] = dp[i-1] + 1;
            ret += dp[i];
        }
        return ret;
    }
};